package com.custom.base.util

import android.text.Html
import android.text.SpannableString
import android.text.Spanned
import android.text.style.StrikethroughSpan
import android.widget.TextView
import java.text.DecimalFormat
import java.util.*

/**
 * 金额util
 */
class MoneyUtil {
    /**
     * 下划线
     */
    fun underLine(money:Double,tv:TextView){
        val sp = SpannableString(Html.fromHtml("&yen ${money}"))
        sp.setSpan(StrikethroughSpan(), 0, Html.fromHtml("&yen ${money}").length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
        tv.text = sp
    }

    /**
     * 格式化数字(保留两位小数)
     *
     * @param money
     * @return
     */
    fun formatNumTwo(money: Any): String {
        val format = DecimalFormat("0.00")
        return format.format(money)
    }

    /**
     * 金额符号
     */
    fun amountSymbol(money:Double,tv:TextView,start:String = "",end:String = ""){
        tv.text = Html.fromHtml("${start} &yen ${money} ${end}")
    }
    /**
     * 符号
     */
    fun symbol(tv:TextView){
        tv.text = Html.fromHtml("&yen ")
    }
}